//package com.ruoyi.framework.config;
//
//import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
//import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
//import com.ruoyi.common.utils.SecurityUtils;
//import org.apache.ibatis.reflection.MetaObject;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.time.LocalDateTime;
//
///**
// * MybatisPlus配置
// *
// * @author tqfeiyang
// * @since 2024/11/28 9:32
// */
//@Configuration
//public class MybatisPlusConfig
//{
//    @Bean
//    public MybatisPlusInterceptor mybatisPlusInterceptor() {
//        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
//        return interceptor;
//    }
//
//    @Bean
//    public MetaObjectHandler commonFieldHandler() {
//        return new MetaObjectHandler() {
//            @Override
//            public void insertFill(MetaObject metaObject) {
//                String currentUserName = SecurityUtils.getUsername();
//                this.strictInsertFill(metaObject, "createBy", () -> currentUserName , String.class);
//                this.strictInsertFill(metaObject, "updateBy", () -> currentUserName, String.class);
//                this.strictInsertFill(metaObject, "createAt", () -> LocalDateTime.now(), LocalDateTime.class);
//                this.strictInsertFill(metaObject, "updateAt", () -> LocalDateTime.now(), LocalDateTime.class);
//                this.strictInsertFill(metaObject, "version", () -> Integer.valueOf(1), Integer.class);
//                this.strictInsertFill(metaObject, "deleted", () -> Boolean.valueOf(false), Boolean.class);
//            }
//
//            @Override
//            public void updateFill(MetaObject metaObject) {
//                String currentUserName = SecurityUtils.getUsername();
//                this.strictUpdateFill(metaObject, "updateBy", () -> currentUserName, String.class);
//                this.strictUpdateFill(metaObject, "updateAt", () -> LocalDateTime.now(), LocalDateTime.class);
//            }
//        };
//    }
//}
